package com.aixx.spingcloud.controller;


import com.aixx.springcloud.entities.CommonResult;
import com.aixx.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.awt.*;

/**
 *
 * @author shkstart
 * @create 2021-01-26 0:26
 */
@RestController
@Slf4j
public class OrderController {
//    远程调用地址      // // 重点是这里，改成 提供者在Eureka 上的名称，而且无需写端口号
    public static final  String PAYMENY_URL = "http://CLOUD-PAYMENT-SERVICE";

    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("customer/payment/create")
    public CommonResult<Payment> create(Payment payment){
/**
 param1 请求地址，param2 请求参数， param3 返回类型
 */
        return restTemplate.postForObject(PAYMENY_URL+"/payment/create",payment,CommonResult.class);
    }
    @GetMapping("customer/payment/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long  id){


        return restTemplate.getForObject(PAYMENY_URL+"/payment/"+id,CommonResult.class);
    }



}
